//
//  Regex.m
//  HappyToday
//
//  Created by Ale (ziming) Lee on 16/8/10.
//  Copyright © 2016年 ziming_lee. All rights reserved.
//

#import "Regex.h"

@implementation Regex

/*正则表达式的解析类的使用
 1. 初始化NSRegularExpression，传入正则表达式
 2. 开始解析 解析结果为数组@[目标字符串在原始字符串中的位置属性]
 3. 截取字符串
 */
+(NSString *)getRegexStringFrom:(NSString *)string withRegularString:(NSString *)regexString{

    //<a href="http://app.weibo.com/t/feed/6ghA0p" rel="nofollow">搜狗高速浏览器</a>
//    NSString *regex = @">.+<";

    // 正则表达式的解析类的使用NSRegularExpression
    NSRegularExpression *regular = [[NSRegularExpression alloc] initWithPattern:regexString options:NSRegularExpressionCaseInsensitive error:nil];

    NSArray *items = [regular matchesInString:string options:NSMatchingReportProgress range:NSMakeRange(0, string.length)];
    for (NSTextCheckingResult *result in items) {

        NSRange range = result.range;
        // 截取字符串
        NSString *subString = [string substringWithRange:range];

        range.location = range.location +1;
        range.length =  range.length-2;

        NSLog(@"%@",subString);
        return subString;
    }


    return nil;
    
}

@end
